package com.wnhz.work.yz.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.MyApplication;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.adapter.YanShouDai2Adapter;
import com.wnhz.work.yz.listener.OnItemClickListener;
import com.yanzhenjie.recyclerview.swipe.Closeable;
import com.yanzhenjie.recyclerview.swipe.OnSwipeMenuItemClickListener;
import com.yanzhenjie.recyclerview.swipe.SwipeMenu;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuCreator;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuItem;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;

public class YanShouChuanActivity extends BaseActivity implements View.OnClickListener {

    private SwipeMenuRecyclerView recycler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yan_shou_chuan);
        TextView title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("上传");
        TextView submit = (TextView) findViewById(R.id.submit);
        submit.setText("上传");
        submit.setVisibility(View.VISIBLE);
        submit.setOnClickListener(this);
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        recycler = (SwipeMenuRecyclerView) findViewById(R.id.recycler);
        recycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    /*    recycler.setAdapter(new BaseRVAdapter(this, MyApplication.test) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_yanshou_chuan;
            }

            @Override
            public void onBind(BaseViewHolder holder, int position) {
                holder.getView(R.id.ll_max).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        startActivity(new Intent(YanShouChuanActivity.this, YanShouChanPinLieBiaoActivity.class));
                    }
                });
            }


        });*/


        initRecycler(recycler);
    }

    public void initRecycler(SwipeMenuRecyclerView recycler_view) {
        recycler_view.setLayoutManager(new LinearLayoutManager(this));
//        recycler_view.setHasFixedSize(true);
//        recycler_view.setItemAnimator(new DefaultItemAnimator());
//        recycler_view.setSwipeMenuCreator(swipeMenuCreator);
//        recycler_view.setSwipeMenuItemClickListener(menuItemClickListener);


        //
        YanShouDai2Adapter adapter = new YanShouDai2Adapter(MyApplication.test, this);
        adapter.setOnItemClickListener(onItemClickListener);

        recycler_view.setAdapter(adapter);
    }

    private OnItemClickListener onItemClickListener = new OnItemClickListener() {
        @Override
        public void onItemClick(int position) {
            //   Toast.makeText(FamilyEditActivity.this, "我是第" + position + "条。", Toast.LENGTH_SHORT).show();
            startActivity(new Intent(YanShouChuanActivity.this, YanShouChanPinLieBiaoActivity.class));

        }
    };
    /**
     * 菜单创建器。
     */
    private SwipeMenuCreator swipeMenuCreator = new SwipeMenuCreator() {
        @Override
        public void onCreateMenu(SwipeMenu swipeLeftMenu, SwipeMenu swipeRightMenu, int viewType) {
            int size = getResources().getDimensionPixelSize(R.dimen.item_height);
            SwipeMenuItem deleteItem = new SwipeMenuItem(YanShouChuanActivity.this)
                    .setText("上传")
                    .setWidth(size)
                    .setTextColor(getResources().getColor(R.color.white))
                    .setBackgroundColor(getResources().getColor(R.color.main_color))
                    .setHeight(dip2px(YanShouChuanActivity.this, 360));

            //      swipeLeftMenu.addMenuItem(deleteItem);
            swipeRightMenu.addMenuItem(deleteItem);

        }
    };


    public int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * 菜单点击监听。
     */
    private OnSwipeMenuItemClickListener menuItemClickListener = new OnSwipeMenuItemClickListener() {
        @Override
        public void onItemClick(Closeable closeable, int adapterPosition, int menuPosition, int direction) {
            closeable.smoothCloseMenu();// 关闭被点击的菜单。

            if (direction == SwipeMenuRecyclerView.RIGHT_DIRECTION) {
                startActivity(new Intent(YanShouChuanActivity.this, YanShouZhengGaiActivity.class));
            }
        }
    };

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
            case R.id.submit:
                startActivity(new Intent(YanShouChuanActivity.this, YanShouZhengGaiActivity.class));
                break;
        }
    }
}
